<template>
    <h2 style="text-align: center;">修改权益信息</h2>
    <table border="1" class="table table-bordered">
        <tbody>
            <tr>
                <th>权益名称</th>
                <th>
                    <input type="text" placeholder="请输入权名称" v-model="Info.MemberRight_Name" />
                </th>
            </tr>

            <tr>
                <th>权益说明</th>
                <th>
                   <textarea cols="20" rows="4" placeholder="请输入权益说明" v-model="Info.MemberRight_Info" ></textarea>
                </th>
            </tr>

            <tr>
                <th>权益状态</th>
                <th>
                    <input type="radio" :value="true" checked v-model="Info.MemberRight_State" />启用
                    <input type="radio" :value="false" v-model="Info.MemberRight_State"  />禁用
                </th>
            </tr>

            <tr>
                <th colspan="2" style="text-align: center;">
                    <input type="button" value="修改权益信息" class="btn btn-success" @click="AddMemberRight" style="margin-right: 10px;"/>
                    <a href="/ShowMemberRight">返回列表</a>
                </th>
            </tr>
        </tbody>
    </table>
</template>


<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import { useRouter ,useRoute} from 'vue-router';

    const router=useRouter();
    const route=useRoute();
    const Info=ref({
        MemberRight_Id:route.params.id,
        MemberRight_Name: "",
        MemberRight_Info: "",
        MemberRight_State: true,
    })

    onMounted(()=>{
        FanTian();//反填
    })
    //反填
    const FanTian=()=>{
        axios.get("https://localhost:44390/api/MemberRight/GetMemberRight?id="+route.params.id)
        .then(res=>{
            Info.value=res.data
        })
    }
    //修改
    const AddMemberRight=()=>{
        axios.put("https://localhost:44390/api/MemberRight/UpdMembeRight",Info.value)
        .then(res=>{
            if(res.data>0)
            {   
                alert('权益信息修改成功');
                router.push("/ShowMemberRight");//跳转到显示页面
            }
            else
            {
                alert('权益信息修改失败');
            }
        })
    }
</script>